using System.Text.RegularExpressions;

namespace FShaderInspector
{
    /// <summary> 表面属性类型 </summary>
    public enum SurfaceType
    {
        Opaque,     // 不透明
        Transparent // 透明
    }

    /// <summary> 混合模式 </summary>
    public enum BlendMode
    {
        Alpha,          // 旧的的阿尔法混合模式，菲涅尔不影响透明度
        Premultiply,    // 物理上合理的透明模式，实现为alpha预乘法
        Additive,       // 添加混合模式
        Multiply        // 相乘混合模式
    }

    /// <summary> 渲染面模式 </summary>
    public enum RenderFace
    {
        Front = 2,  // 正面
        Back = 1,   // 背面
        Both = 0    // 双面
    }

    /// <summary> 通用渲染标签 </summary>
    public static class CommonTags
    {
        // 渲染队列标签
        public const string Queue = "Queue";
        public const string Queue_Background = "Background";     // 背景         1000
        public const string Queue_Geometry = "Geometry";         // 几何         2000
        public const string Queue_AlphaTest = "AlphaTest";       // Alpha测试    2450
        public const string Queue_Transparent = "Transparent";   // 透明         3000
        public const string Queue_Overlay = "Overlay";           // 覆盖         4000

        // RenderType 标签
        public const string RenderType = "RenderType";
        public const string RenderType_Opaque = "Opaque";
        public const string RenderType_Transparent = "Transparent";
        public const string RenderType_Overlay = "Overlay";
        public const string RenderType_TransparentCutout = "TransparentCutout";
        public const string RenderType_Background = "Background";
        public const string RenderType_TreeOpaque = "TreeOpaque";
        public const string RenderType_TreeTransparentCutout = "TreeTransparentCutout";
        public const string RenderType_TreeBillboard = "TreeBillboard";
        public const string RenderType_Grass = "Grass";
        public const string RenderType_GrassBillboard = "GrassBillboard";
    }

    /// <summary> 表面属性关键字 </summary>
    public static class CommonProperty
    {
        /// <summary> 选项 -- 表面类型 Opaque Transparent </summary>
        public const string SurfaceType = "_Surface";

        /// <summary> 选项 -- 表面类型 混合模式 Alpha Premultiply... </summary>
        public const string BlendMode = "_Blend";

        /// <summary> 属性 -- _SrcBlend </summary>
        public const string SrcBlend = "_SrcBlend";

        /// <summary> 属性 -- _SrcBlendAlpha </summary>
        public const string SrcBlendAlpha = "_SrcBlendAlpha";

        /// <summary> 属性 -- _DstBlend </summary>
        public const string DstBlend = "_DstBlend";

        /// <summary> 属性 -- _DstBlendAlpha </summary>
        public const string DstBlendAlpha = "_DstBlendAlpha";

        /// <summary> 选项 -- 混合模式保持高光 </summary>
        public const string BlendModePreserveSpecular = "_BlendModePreserveSpecular";

        /// <summary> 选项 -- Alpha测试 </summary>
        public const string AlphaClip = "_AlphaClip";

        /// <summary> 属性 -- Alpha测试阈值 </summary>
        public const string Cutoff = "_Cutoff";

        /// <summary> 属性 -- _AlphaToMask </summary>
        public const string AlphaToMask = "_AlphaToMask";

        /// <summary> 属性 -- _ZWrite 深度写入 </summary>
        public const string ZWrite = "_ZWrite";

        /// <summary> 属性 -- _ZTest 深度测试 </summary>
        public const string ZTest = "_ZTest";

        /// <summary> 选项 -- 面剔除模式 </summary>
        public const string Cull = "_Cull";

        /// <summary> 选项 -- 接收阴影 </summary>
        public const string ReceiveShadows = "_ReceiveShadows";

        /// <summary> 选项 -- 反射高光 </summary>
        public const string SpecularHighlights = "_SpecularHighlights";

        /// <summary> 选项 -- 环境反射 </summary>
        public const string EnvironmentReflections = "_EnvironmentReflections";

        /// <summary> 属性 -- 队列偏移 </summary>
        public const string QueueOffset = "_QueueOffset";
    }

    /// <summary> 通用宏 </summary>
    public static class CommonKeyword
    {
        /// <summary> 表面类型 不透明 透明 </summary>
        public const string SurfaceTypeTransparent = "_SURFACE_TYPE_TRANSPARENT";

        /// <summary> Alpha预乘 </summary>
        public const string AlphaPreMultiplyOn = "_ALPHAPREMULTIPLY_ON";

        /// <summary> Alpha调节 </summary>
        public const string AlphaModulate = "_ALPHAMODULATE_ON";

        /// <summary> AlphaTes测试 </summary>
        public const string AlphaTestOn = "_ALPHATEST_ON";

        /// <summary> 接收阴影 </summary>
        public const string ReceiveShadowsOff = "_RECEIVE_SHADOWS_OFF";

        /// <summary> 反射高光 </summary>
        public const string SpecularHighlightsOff = "_SPECULARHIGHLIGHTS_OFF";

        /// <summary> 环境反射 </summary>
        public const string EnvironmentReflectionsOff = "_ENVIRONMENTREFLECTIONS_OFF";
    }

    /// <summary> 通用 pass 名 </summary>
    public static class CommonPassName
    {
        /// <summary> 深度Pass </summary>
        public const string DepthOnly = "DepthOnly";

        /// <summary> 阴影Pass </summary>
        public const string ShadowCaster = "ShadowCaster";
    }

    /// <summary> string 常用工具 </summary>
    public static class StringUtils
    {
        /// <summary> 获取小括号内容 </summary>
        /// <param name="str">字符串</param> <returns>字符串</returns>
        public static string GetLittleBracketsValue(string str)
        {
            if (str.Contains("(") && str.Contains(")"))
                return Regex.Replace(str, @"(.*\()(.*)(\).*)", "$2");

            return string.Empty;
        }

        /// <summary> 获取方括号内容 </summary>
        /// <param name="str">字符串</param> <returns>字符串</returns>
        public static string GetSquareBrackets(string str)
        {
            var rgx = new Regex(@"(?i)(?<=\[)(.*)(?=\])");
            return rgx.Match(str).Value;
        }

        /// <summary> 获取大括号内容 </summary>
        /// <param name="str"> 字符串</param> <returns>字符串</returns>
        public static string GetBigBracketsValue(string str)
        {
            return Regex.Match(str, @"\{(.*)\}", RegexOptions.Singleline).Groups[1].Value;
        }
    }
}